package it.softphone.cmc.server.entity;

import it.softphone.cmc.shared.entity.Attributes;
import it.softphone.cmc.shared.entity.Transaction;
import it.softphone.commons.service.LogAware;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;

@Entity
public class TransactionEntity implements Transaction, LogAware {
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY) 
	private Long id;

	@Embedded 
	@OneToOne(cascade=CascadeType.ALL)
	private AttributesEntity attributes = new AttributesEntity();
	
	private String userAgent = "";

	//@Column(nullable=false) @Temporal(TemporalType.TIMESTAMP)
	private java.util.Date date = new Date();;
	
	private String userId = "";
	private String refId = "";

	private String type = "";
	private String subType = "";
	
	private double lat = 0;
	private double lng = 0;
	
	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("TransactionEntity [id=").append(id)
				.append(", attributes=").append(attributes)
				.append(", userAgent=").append(userAgent).append(", date=")
				.append(date).append(", userId=").append(userId)
				.append(", type=").append(type).append("]");
		return builder.toString();
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getId()
	 */
	@Override
	public final Long getId() {
		return id;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setId(java.lang.Long)
	 */
	@Override
	public final void setId(Long id) {
		this.id = id;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getUserAgent()
	 */
	@Override
	public final String getUserAgent() {
		return userAgent;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setUserAgent(java.lang.String)
	 */
	@Override
	public final void setUserAgent(String userAgent) {
		this.userAgent = userAgent;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getUserId()
	 */
	@Override
	public final String getUserId() {
		return userId;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setUserId(java.lang.String)
	 */
	@Override
	public final void setUserId(String userId) {
		this.userId = userId;
	}
	
	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getType()
	 */
	@Override
	public final String getType() {
		return type;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setType(java.lang.String)
	 */
	@Override
	public final void setType(String type) {
		this.type = type;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getSubType()
	 */
	@Override
	public final String getSubType() {
		return subType;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setSubType(java.lang.String)
	 */
	@Override
	public final void setSubType(String subType) {
		this.subType = subType;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getRefId()
	 */
	@Override
	public final String getRefId() {
		return refId;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setRefId(java.lang.String)
	 */
	@Override
	public final void setRefId(String refId) {
		this.refId = refId;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getLat()
	 */
	@Override
	public final double getLat() {
		return lat;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setLat(double)
	 */
	@Override
	public final void setLat(double lat) {
		this.lat = lat;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#getLng()
	 */
	@Override
	public final double getLng() {
		return lng;
	}

	/* (non-Javadoc)
	 * @see it.softphone.cmc.entity.Transaction#setLng(double)
	 */
	@Override
	public final void setLng(double lng) {
		this.lng = lng;
	}

	@Override
	public Attributes getAttributes() {
		return attributes;
	}


	@Override
	public void setAttributes(Attributes value) {
		attributes = (AttributesEntity) value;
		
	}

	@Override
	public Date getDate() {
		return date;
	}

	@Override
	public void setDate(Date value) {
		date = value;
	}

	@SuppressWarnings("unchecked")
	@Override
	public it.softphone.commons.json.server.JSONObject encodeAttributes() {	
		return  attributes.encodeAttributes();
	}

	@Override
	public void decodeAttributes(Object object) {
		attributes.decodeAttributes(object);
	}
	
	
}
